/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CreateSupplier.java
 *
 * Created on 16-06-2011, 13:15:16
 */
package GUILayer;
import ControlLayer.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Alex
 */
public class CreateSupplier extends javax.swing.JFrame {
    private SupplierController supplierController;

    /** Creates new form CreateSupplier */
    public CreateSupplier() {
        initComponents();
        supplierController = new SupplierController();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        createSupplierPanel1 = new javax.swing.JPanel();
        tekstToSupplierLabel1 = new javax.swing.JLabel();
        enterSupplierNameLabel1 = new javax.swing.JLabel();
        enterSupplierAddrssLabel1 = new javax.swing.JLabel();
        enterSupplierCityLabel1 = new javax.swing.JLabel();
        enterZIPCodeLabel1 = new javax.swing.JLabel();
        enterPhoneNumberLabel1 = new javax.swing.JLabel();
        enterDeliveryTimeLabel1 = new javax.swing.JLabel();
        enterDeliveryTimeTextField1 = new javax.swing.JTextField();
        enterSupplierPhoneNumberTextField1 = new javax.swing.JTextField();
        enterSupplierZIPcodeTextField1 = new javax.swing.JTextField();
        enterSupplierCityTextField1 = new javax.swing.JTextField();
        enterSupplierAddressTextField2 = new javax.swing.JTextField();
        enterSupplierNameTextField2 = new javax.swing.JTextField();
        createSupplierOkayButton1 = new javax.swing.JButton();
        cancelCreateSupplierButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        createSupplierPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Create supplier"));

        tekstToSupplierLabel1.setText("Enter supplier information:");

        enterSupplierNameLabel1.setText("Enter name:");

        enterSupplierAddrssLabel1.setText("Enter address:");

        enterSupplierCityLabel1.setText("Enter city:");

        enterZIPCodeLabel1.setText("Enter ZIP code:");

        enterPhoneNumberLabel1.setText("Enter phone number:");

        enterDeliveryTimeLabel1.setText("Enter delivery time:");

        enterSupplierAddressTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enterSupplierAddressTextField2ActionPerformed(evt);
            }
        });

        createSupplierOkayButton1.setText("Create");
        createSupplierOkayButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createSupplierOkayButton1ActionPerformed(evt);
            }
        });

        cancelCreateSupplierButton1.setText("Cancel");
        cancelCreateSupplierButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelCreateSupplierButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout createSupplierPanel1Layout = new javax.swing.GroupLayout(createSupplierPanel1);
        createSupplierPanel1.setLayout(createSupplierPanel1Layout);
        createSupplierPanel1Layout.setHorizontalGroup(
            createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(createSupplierPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(createSupplierPanel1Layout.createSequentialGroup()
                        .addComponent(tekstToSupplierLabel1)
                        .addContainerGap(219, Short.MAX_VALUE))
                    .addGroup(createSupplierPanel1Layout.createSequentialGroup()
                        .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(createSupplierPanel1Layout.createSequentialGroup()
                                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(enterDeliveryTimeLabel1)
                                    .addComponent(enterPhoneNumberLabel1)
                                    .addComponent(enterZIPCodeLabel1)
                                    .addComponent(enterSupplierAddrssLabel1)
                                    .addComponent(enterSupplierCityLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 30, Short.MAX_VALUE)
                                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(enterSupplierNameTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(enterSupplierAddressTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(enterSupplierCityTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(enterSupplierZIPcodeTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(enterSupplierPhoneNumberTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(enterDeliveryTimeTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(createSupplierPanel1Layout.createSequentialGroup()
                                        .addComponent(createSupplierOkayButton1)
                                        .addGap(18, 18, 18)
                                        .addComponent(cancelCreateSupplierButton1))))
                            .addGroup(createSupplierPanel1Layout.createSequentialGroup()
                                .addComponent(enterSupplierNameLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(66, 66, 66))))
        );
        createSupplierPanel1Layout.setVerticalGroup(
            createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(createSupplierPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(tekstToSupplierLabel1)
                .addGap(18, 18, 18)
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterSupplierNameLabel1)
                    .addComponent(enterSupplierNameTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterSupplierAddrssLabel1)
                    .addComponent(enterSupplierAddressTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterSupplierCityLabel1)
                    .addComponent(enterSupplierCityTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterZIPCodeLabel1)
                    .addComponent(enterSupplierZIPcodeTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterPhoneNumberLabel1)
                    .addComponent(enterSupplierPhoneNumberTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterDeliveryTimeLabel1)
                    .addComponent(enterDeliveryTimeTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(createSupplierPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(createSupplierOkayButton1)
                    .addComponent(cancelCreateSupplierButton1))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(createSupplierPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(createSupplierPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void enterSupplierAddressTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enterSupplierAddressTextField2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_enterSupplierAddressTextField2ActionPerformed

    private void cancelCreateSupplierButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelCreateSupplierButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelCreateSupplierButton1ActionPerformed

    private void createSupplierOkayButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createSupplierOkayButton1ActionPerformed
        try{
        supplierController.createSupplier(enterSupplierNameTextField2.getText(), enterSupplierAddressTextField2.getText(), enterSupplierCityTextField1.getText(), Integer.parseInt(enterSupplierZIPcodeTextField1.getText()), Integer.parseInt(enterSupplierPhoneNumberTextField1.getText()), enterDeliveryTimeTextField1.getText());
        }catch(Exception e){
            System.out.println("Create supplier failed, check inputtypes int,string, ect.");
        }
        this.dispose();
    }//GEN-LAST:event_createSupplierOkayButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CreateSupplier().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelCreateSupplierButton1;
    private javax.swing.JButton createSupplierOkayButton1;
    private javax.swing.JPanel createSupplierPanel1;
    private javax.swing.JLabel enterDeliveryTimeLabel1;
    private javax.swing.JTextField enterDeliveryTimeTextField1;
    private javax.swing.JLabel enterPhoneNumberLabel1;
    private javax.swing.JTextField enterSupplierAddressTextField2;
    private javax.swing.JLabel enterSupplierAddrssLabel1;
    private javax.swing.JLabel enterSupplierCityLabel1;
    private javax.swing.JTextField enterSupplierCityTextField1;
    private javax.swing.JLabel enterSupplierNameLabel1;
    private javax.swing.JTextField enterSupplierNameTextField2;
    private javax.swing.JTextField enterSupplierPhoneNumberTextField1;
    private javax.swing.JTextField enterSupplierZIPcodeTextField1;
    private javax.swing.JLabel enterZIPCodeLabel1;
    private javax.swing.JLabel tekstToSupplierLabel1;
    // End of variables declaration//GEN-END:variables
}
